package com.briup.mt.service.impl;

import com.briup.mt.bean.DatasetFile;
import com.briup.mt.bean.DatasetFileExample;
import com.briup.mt.dao.DatasetFileMapper;
import com.briup.mt.service.IFiledatasetFilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author lijiaojiao
 * @version 1.0
 * @date 2020/12/16 11:09
 */
@Service
public class FileDatasetFileServiceImpl implements IFiledatasetFilesService {
    @Autowired
    private DatasetFileMapper datasetFileMapper;
    @Override
    public List<DatasetFile> query(String name, Long datasetId){
        DatasetFileExample example = new DatasetFileExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andFileRealNameLike("%"+name+"%");
        }
        if(datasetId != null){
            example.createCriteria().andDatasetIdEqualTo(datasetId);
        }
        return datasetFileMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(DatasetFile datasetFile){
        if (datasetFile.getId() == null) {
            datasetFileMapper.insert(datasetFile);
        }else{
            datasetFileMapper.updateByPrimaryKey(datasetFile);
        }
    }

    @Override
    public void deleteById(long id) {

        datasetFileMapper.deleteByPrimaryKey(id);
    }
}

